// 封装静态web服务
const fs = require('fs')
const mime = require('mime')
exports.static = function(req, res, staticPath) {
    if(req.url != '/favicon.ico') {
        
        let file = req.url
        file = file == '/' ? '/index.html' : file

        const type = (mime.getType(file))
    
        fs.readFile('./static' + file, (err, data ) => {
            if(err) {
                res.writeHead(400,{'content-type':'' + type + ';charset="utf-8"'})
                res.end('访问出现错误')
                console.log(err)
                return 
            }
            res.writeHead(200, {'content-type':'' + type + ';charset=UTF-8'})
            res.end(data)
        })
    }
}